using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PcSms
{
    public partial class MainForm : Form
    {
        OpenNETCF.Desktop.Communication.RAPI api;

        public MainForm()
        {
            api = new OpenNETCF.Desktop.Communication.RAPI();
            InitializeComponent();
        }

        private void sendBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if ( !api.Connected )
                {
                    api.Connect();
                }

                string prucpath = System.Configuration.ConfigurationSettings.AppSettings["winMobSmsPath"];

                api.CreateProcess(prucpath, this.numBox.Text.Trim() + " " + msgBox.Text.Trim());

                if ( api.Connected )
                {
                    api.Disconnect();
                }
            }
            catch ( Exception ee )
            {
                MessageBox.Show(ee.Message);

            }
        }

        private void numBox_TextChanged(object sender, EventArgs e)
        {
            numBox.Text = System.Text.RegularExpressions.Regex.Replace(numBox.Text, @"\D", "");
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            AddTel();
        }

        private void AddTel()
        {
            try
            {
                string telpath = System.Configuration.ConfigurationSettings.AppSettings["telPath"];
                if (!System.IO.File.Exists(telpath))
                {
                    return;
                }

                string[] tels = System.IO.File.ReadAllLines(telpath, System.Text.Encoding.Default);
                this.telsBox.DataSource = tels;
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }

        }

        private void telsBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            numBox.Text = telsBox.SelectedValue as string;
        }
    }
}
